local mouke = fk.CreateSkill {
  name = "lingling__mouke",
  tags = { Skill.Switch },
}

Fk:loadTranslationTable{
  ["lingling__mouke"] = "谋克",
  [":lingling__mouke"] = "转换技，出牌阶段限一次，阳：你可以摸一张牌，然后弃置两张手牌；阴：你可以摸两张牌，然后弃置一张手牌。"..
  "若如此做，你于此阶段内使用与你以此法弃置的牌花色相同的牌无距离和次数限制。",

  [":lingling__mouke_yang"] = "转换技，出牌阶段限一次，"..
  "<font color=\"#E0DB2F\">阳：你可以摸一张牌，然后弃置两张手牌；</font>" ..
  "阴：你可以摸两张牌，然后弃置一张手牌。"..
  "若如此做，你于此阶段内使用与你以此法弃置的牌花色相同的牌无距离和次数限制。",
  [":lingling__mouke_yin"] = "转换技，出牌阶段限一次，"..
  "阳：你可以摸一张牌，然后弃置两张手牌；"..
  "<font color=\"#E0DB2F\">阴：你可以摸两张牌，然后弃置一张手牌。</font>"..
  "若如此做，你于此阶段内使用与你以此法弃置的牌花色相同的牌无距离和次数限制。",

  ["#lingling__mouke"] = "谋克：摸%arg张牌，弃置%arg2张手牌，本阶段使用这些花色的牌无距离次数限制",
  ["#lingling__mouke-discard"] = "谋克：弃置%arg张手牌，本阶段使用这些花色的牌无距离和次数限制",
  ["@lingling__mouke-phase"] = "谋克",
}

mouke:addEffect("active", {
  anim_type = "switch",
  prompt = function (self, player)
    return player:getSwitchSkillState(mouke.name, false) == fk.SwitchYang and "#lingling__mouke:::1:2" or "#lingling__mouke:::2:1"
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(mouke.name, Player.HistoryPhase) < 1
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local isYang = player:getSwitchSkillState(mouke.name, true) == fk.SwitchYang

    player:drawCards(isYang and 1 or 2, mouke.name)
    if player.dead then return end

    local num = isYang and 2 or 1
    local toDiscard = room:askToDiscard(player, {
      min_num = num,
      max_num = num,
      include_equip = false,
      skill_name = mouke.name,
      cancelable = false,
      prompt = "#lingling__mouke-discard:::"..num,
      skip = true,
    })
    if #toDiscard == 0 then return end

    for _, id in ipairs(toDiscard) do
      local suit = Fk:getCardById(id):getSuitString(true)
      if suit ~= "log_nosuit" then
        room:addTableMarkIfNeed(player, "@lingling__mouke-phase", suit)
      end
    end
    room:throwCard(toDiscard, mouke.name, player, player)
  end,
})

mouke:addEffect(fk.PreCardUse, {
  can_refresh = function(self, event, target, player, data)
    return target == player and table.contains(player:getTableMark("@mouke-phase"), data.card:getSuitString(true))
  end,
  on_refresh = function(self, event, target, player, data)
    data.extraUse = true
  end,
})

mouke:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card)
    return card and table.contains(player:getTableMark("@lingling__mouke-phase"), card:getSuitString(true))
  end,
  bypass_distances = function(self, player, skill, card)
    return card and table.contains(player:getTableMark("@lingling__mouke-phase"), card:getSuitString(true))
  end,
})

return mouke
